<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page language="java" import="java.util.*,java.text.SimpleDateFormat, com.bean.library.StatisticPaper,
	com.bean.library.Course, com.bean.library.Teacher"%>
<jsp:useBean id="teacher" class="com.bean.library.Teacher" scope="session"></jsp:useBean> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
	String teacherName = teacher.getTeacherName();
	HttpSession s = request.getSession();
%>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Check Paper</title>
    <link rel="stylesheet" href="../t_css/t_common.css" type="text/css" />
    <link rel="stylesheet" href="../t_css/t_left_course.css" type="text/css" />
    <link rel="stylesheet" href="../t_css/t_checkpaper.css" type="text/css" />
    <script type="text/javascript" src="../scripts/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="../scripts/jquery.animate-colors-min.js"></script>
    <script type="text/javascript" src="../t_scripts/t_navi_common.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#choose_logo").hover(function () {
                $(this).animate({ backgroundColor: '#30A8F4' }, { speed: 1000, queue: false });
            }, function () {
                $(this).animate({ backgroundColor: '#C35A33' }, { speed: 1000, queue: false });
            });
            var btns = ["btn_exam_info", "btn_convert", "btn_check_content"];
            var oldColor;
            $(btns).each(function (key,value) {
                $("." + value).hover(function () {
                    oldColor = $(this).css('background-color');
                    $(this).animate({ backgroundColor: '#30A8F4' }, { speed: 1000, queue: false });
                }, function () {
                    $(this).animate({ backgroundColor: oldColor }, { speed: 1000, queue: false });
                });
            });
            var up_hrefColor = $("#href_up").css('color');
            var down_hrefColor = $("#href_down").css('color');
            $("#page_up").hover(function () {
            	$("#submit_page_num").val(parseInt($("#page_num").val(),10)-1);
                $("#href_up").animate({ color: '#000000' }, 0);
            }, function () {
                $("#href_up").animate({ color: up_hrefColor }, 0);
            });

            $("#page_down").hover(function () {
            	$("#submit_page_num").val(parseInt($("#page_num").val(),10)+1);
                $("#href_down").animate({ color: '#000000' }, 0);
            }, function () {
                $("#href_down").animate({ color: down_hrefColor }, 0);
            });
            
            /*$(".btn_exam_info").click(function(){
            	window.location.href = "t_exam_info.htm";
            });*/
            $(".btn_check_content").click(function(){
            	window.location.href = "t_paperContent.htm";
            });
            
            /**********翻页区域***************/
            var page_num = parseInt($("#page_num").val(),10);
            var max_page_num = parseInt($("#max_page_num").val(),10);
            
            $("#page_up").click(function(){
            	if(page_num <= 1){
            		return false;
            	}
            	$("#page_turning_form").submit();
            });
            $("#page_down").click(function(){
            	if(page_num >= max_page_num){
            		return false;
            	}
            	$("#page_turning_form").submit();
            });
            
            ////////////////////////////////////
            var stretch = $("#ui_need").val();
            if(stretch == "stretch"){
            	$("#content_exam").css("height",$("#content_left").css("height"));
            }
        });
    </script>
</head>
<body>
<div id="bigContent">
<div id="head">
    <div id="title">
        <div class="title_left">
            <div class="titleText">Students Online Exam Platform ( For Teacher )</div>
        </div>
        <div class="title_right">
            <div class="avatar"><img src="../image/noavatar.jpg" alt="../image/noavatar.jpg"/></div>
            <div class="userState">
                <div class="userState_big"><a href="#"><%=teacherName %></a></div>
                <div class="userState_small"><a href="/Exam1/servlet/TLogoutServlet">logout</a></div>
            </div>
        </div>
    </div>
    <div id="navi">
    <form id="navi_form" action="/Exam1/servlet/TNaviSelectServlet" method="post">
        <div class="navi_top">
            <ul class="all_navi">
            	<li id="navi1" class="each_navi navi1">Set Questions</li>
                <li id="navi2" class="each_navi navi2">Check Paper</li>
            </ul>
        </div>
        <div class="navi_bottom">
            <ul class="all_courses">
            	<%
            	ArrayList<Course> teacherCourseList = teacher.getTeacherCourseList();
            	Iterator<Course> teacherCourseIt = teacherCourseList.iterator();
            	int courseNum = 0;
            	while(teacherCourseIt.hasNext()){
            		courseNum++;
            		Course course = teacherCourseIt.next();
            		String courseName = course.getCourseName();
            		String courseId = course.getCourseId();
            	
            	%>
            	<li class="each_course course<%=courseNum%>" id="<%=courseId%>"><%=courseName %></li>
            	<%} %>
            </ul>
        </div>
        <input type="hidden" id="operate_type" name="operate_type" value=""/>
        <input type="hidden" id="course_id" name="course_id" value=""/>
        <input type="hidden" id="course_name" name="course_name" value=""/>
    </form> 
    </div>
</div>
<div id="content_exam"  class="boxShadow">
    <div id="choose_logo">
        <div class="choose_logo_text">Check Paper</div>
        <div class="choose_logo_img"></div>
    </div>
    <div id="content_left">
        <div id="courses">
            <div id="courses_title">Courses</div>
            <form id="course_form" action="/Exam1/servlet/TCourseSelectServlet" method="post">
	            <div id="courses_details">
	                <ul id="courses_list">
	                	<%  courseNum = 0;
	                		Iterator<Course> teacherCourseIt1 = teacherCourseList.iterator();
	                		while(teacherCourseIt1.hasNext()){
	                		courseNum++;
	                		Course course = teacherCourseIt1.next();
	                		String courseName = course.getCourseName();
	                		String courseId = course.getCourseId(); %>
	                    <li class="li<%=courseNum%>" id="<%=courseId%>"><div class="each_course_text"><%=courseName %></div></li>
	                    <%} %>
	                </ul>
	                <input type="hidden" id="li_count" value="<%=courseNum%>"/>
	            </div>
	           	<input type="hidden" value="" id="select_course" name="select_course"/>
	            <input type="hidden" value="" id="select_course_name" name="select_course_name"/>
	            <input type="hidden" value="checkpaper" id="test_type" name="operate_type"/>
            </form>
        </div>
    </div>
    <div id="content_right">
    	<%if(s.getAttribute("selectedCourseId")!=null){    		
    		String courseName = (String)s.getAttribute("selectedCourseName");
		%>
		<div id="subjects_name"><%=courseName%></div>
		<%
    		ArrayList<StatisticPaper> examPaperList = (ArrayList<StatisticPaper>)s.getAttribute("examPaperList");
    		ArrayList<StatisticPaper> sparePaperList = (ArrayList<StatisticPaper>)s.getAttribute("sparePaperList");
    		ArrayList<StatisticPaper> modelPaperList = (ArrayList<StatisticPaper>)s.getAttribute("modelPaperList");
    		int startIndex = (Integer)s.getAttribute("startIndex");
    		int beginIndex = startIndex;
    		startIndex *= 5;
    		int endIndex = startIndex + 4;
    		int[] point = new int[4];
    		point[0] = 0;
			point[1] = 1;
			point[2] = 1 + sparePaperList.size();
			point[3] = point[2] + modelPaperList.size();
			//////////////////////////////
        	int prePageNum = beginIndex;
        	int nextPageNum = beginIndex + 2;
        	int curPageNum = beginIndex + 1; 
        	int totalSize = point[3];
        	int maxPageNum = (totalSize%5==0)?(totalSize/5):(totalSize/5 + 1);
			///////////////////////
			StatisticPaper examPaper = examPaperList.get(0);
			String examPaperName = examPaper.getPaperName();
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String examPaperCreationTime = df.format(examPaper.getCreationTime());
			int examPaperSubmitNum = examPaper.getSubmitNumber();
			int examPaperId = examPaper.getPaperId();
			if(startIndex < 1){
    	%>
        <div id="exam_paper" class="exam_paper">
            <div id="exam_paper_mark" class="exam_paper_mark">Exam Paper</div>
            <div id="exam_paper1" class="paper">
                <div id="exam_paper1_title" class="paper_title"><%=examPaperName%></div>
                <div id="exam_paper1_details" class="paper_details">
                    <div id="exam_paper1_create_time" class="paper_create_time">creation time:<%=examPaperCreationTime %></div>
                    <div id="exam_paper1_submit_number" class="paper_submit_number">submit number:<%=examPaperSubmitNum %></div>
                </div>
                <div id="exam_paper1_operate" class="paper_operate">
                    <form action="/Exam1/servlet/TCheckExamInfoServlet" method="post" class="exam_info_form">
                        <input type="submit" class="btn_exam_info" value="Check Exam Info"/>
                        <input type="hidden" name="paper_id" value="<%=examPaperId%>"/>
                        <input type="hidden" name="paper_name" value="<%=examPaperName%>"/>
                    </form>  
                    <form action="/Exam1/servlet/TCheckPaperContentServlet" method="post">  
                        <input type="submit" class="btn_check_content" value="Check Content"/>
                        <input type="hidden" name="paper_id" value="<%=examPaperId%>"/>
                    </form>    
                </div>
            </div>
        </div>
        <% if(sparePaperList.size() >= 4){ %>        
        <div id="spare_paper" class="spare_paper">
            <div id="spare_paper_mark" class="spare_paper_mark">Spare Paper</div>
            <%for(int i = 0;i<4;i++){ 
            	StatisticPaper sparePaper = sparePaperList.get(i);
            	String sparePaperName = sparePaper.getPaperName();
            	int sparePaperId = sparePaper.getPaperId();
            	String sparePaperCreationTime  = df.format(sparePaper.getCreationTime());
            	int sparePaperSubmitNum = sparePaper.getSubmitNumber();
            %>
            <div class="spare_paper_content">
                <div class="paper_title"><%=sparePaperName %></div>
                <div class="paper_details">
                    <div class="paper_create_time">creation time:<%=sparePaperCreationTime %></div>
                    <div class="paper_submit_number">submit number:<%=sparePaperSubmitNum %></div>
                </div>
                <div class="spare_paper_operate">
                    <form action="#" method="post" class="convert_to_form">
                        <input type="button" class="btn_convert" value="Convert to Exam Paper"/>
                    </form>
                    <form action="/Exam1/servlet/TCheckPaperContentServlet" method="post">  
                        <input type="submit" class="btn_check_content" value="Check Content"/>
                        <input type="hidden" name="paper_id" value="<%=sparePaperId%>"/>
                    </form> 
                </div>
            </div>
            <%} %>
        </div>
        <%}else{ %>
        <div id="spare_paper" class="spare_paper">
            <div id="spare_paper_mark" class="spare_paper_mark">Spare Paper</div>
        <%for(int i = 0;i<sparePaperList.size();i++){ 
        	StatisticPaper sparePaper = sparePaperList.get(i);
        	String sparePaperName = sparePaper.getPaperName();
        	int sparePaperId = sparePaper.getPaperId();
        	String sparePaperCreationTime  = df.format(sparePaper.getCreationTime());
        	int sparePaperSubmitNum = sparePaper.getSubmitNumber();
        %>    
            <div class="spare_paper_content">
                <div class="paper_title"><%=sparePaperName %></div>
                <div class="paper_details">
                    <div class="paper_create_time">creation time:<%=sparePaperCreationTime %></div>
                    <div class="paper_submit_number">submit number:<%=sparePaperSubmitNum %></div>
                </div>
                <div class="spare_paper_operate">
                    <form action="#" method="post" class="convert_to_form">
                        <input type="button" class="btn_convert" value="Convert to Exam Paper"/>
                    </form>
                    <form action="/Exam1/servlet/TCheckPaperContentServlet" method="post">  
                        <input type="submit" class="btn_check_content" value="Check Content"/>
                        <input type="hidden" name="paper_id" value="<%=sparePaperId%>"/>
                    </form> 
                </div>
            </div>            
       	<%} %>    
        </div>    
        <div id="practice_paper" class="practice_paper">
	        <div id="practice_paper_mark" class="practice_paper_mark">Practice Paper</div>
	    <%for(int i = 0;i<(4 -sparePaperList.size());i++){ 
        	StatisticPaper practicePaper = sparePaperList.get(i);
        	String practicePaperName = practicePaper.getPaperName();
        	int practicePaperId = practicePaper.getPaperId();
        	String practicePaperCreationTime  = df.format(practicePaper.getCreationTime());
        	int practicePaperSubmitNum = practicePaper.getSubmitNumber();	    	
	    %>                
	        <div class="practice_paper_content">
		        <div class="paper_title"><%=practicePaperName %></div>
		        <div class="paper_details">
			        <div class="paper_create_time">creation time:<%=practicePaperCreationTime %></div>
			        <div class="paper_submit_number">submit number:<%=practicePaperSubmitNum %></div>
		        </div>
		        <div class="practice_paper_operate">
			        <form action="/Exam1/servlet/TCheckPaperContentServlet" method="post">
				        <input type="submit" class="btn_check_content" value="Check Content"/>
				        <input type="hidden" name="paper_id" value="<%=practicePaperId%>"/>				        
			        </form>
		        </div>
	        </div>
	    <%} %>                
        </div>    
        <%}}else if(startIndex < point[2] && endIndex <=point[2]){%>
        <div id="spare_paper" class="spare_paper">
            <div id="spare_paper_mark" class="spare_paper_mark">Spare Paper</div>
        	<%for(int i = startIndex - 1;i<startIndex + 4;i++){ 
            	StatisticPaper sparePaper = sparePaperList.get(i);
            	String sparePaperName = sparePaper.getPaperName();
            	int sparePaperId = sparePaper.getPaperId();
            	String sparePaperCreationTime  = df.format(sparePaper.getCreationTime());
            	int sparePaperSubmitNum = sparePaper.getSubmitNumber();        	
        	%>            
            <div class="spare_paper_content">
                <div class="paper_title"><%=sparePaperName %></div>
                <div class="paper_details">
                    <div class="paper_create_time">creation time:<%=sparePaperCreationTime %></div>
                    <div class="paper_submit_number">submit number:<%=sparePaperSubmitNum %></div>
                </div>
                <div class="spare_paper_operate">
                    <form action="#" method="post" class="convert_to_form">
                        <input type="button" class="btn_convert" value="Convert to Exam Paper"/>
                    </form>
                    <form action="/Exam1/servlet/TCheckPaperContentServlet" method="post">  
                        <input type="submit" class="btn_check_content" value="Check Content"/>
                        <input type="hidden" name="paper_id" value="<%=sparePaperId%>"/>
                    </form>
                </div>
            </div>        
            <%} %>
        </div>
        <%}else if(startIndex < point[2] && endIndex > point[2]){ %>
        <div id="spare_paper" class="spare_paper">
            <div id="spare_paper_mark" class="spare_paper_mark">Spare Paper</div>
            <%for(int i = startIndex - 1;i< sparePaperList.size();i++){ 
            	StatisticPaper sparePaper = sparePaperList.get(i);
            	String sparePaperName = sparePaper.getPaperName();
            	int sparePaperId = sparePaper.getPaperId();
            	String sparePaperCreationTime  = df.format(sparePaper.getCreationTime());
            	int sparePaperSubmitNum = sparePaper.getSubmitNumber();            
            %>
            <div class="spare_paper_content">
                <div class="paper_title"><%=sparePaperName %></div>
                <div class="paper_details">
                    <div class="paper_create_time">creation time:<%=sparePaperCreationTime %></div>
                    <div class="paper_submit_number">submit number:<%=sparePaperSubmitNum %></div>
                </div>
                <div class="spare_paper_operate">
                    <form action="#" method="post" class="convert_to_form">
                        <input type="button" class="btn_convert" value="Convert to Exam Paper"/>
                    </form>
                    <form action="/Exam1/servlet/TCheckPaperContentServlet" method="post">  
                        <input type="submit" class="btn_check_content" value="Check Content"/>
                        <input type="hidden" name="paper_id" value="<%=sparePaperId%>"/>
                    </form>
                </div>
            </div>  
            <%} %>            
        </div>
      	<div id="practice_paper" class="practice_paper">
	        <div id="practice_paper_mark" class="practice_paper_mark">Practice Paper</div>
	        <%
	        	int  tmp = ((point[3] - point[2])<(endIndex - point[2]))?(point[3] - point[2]):(endIndex - point[2]);
	        	if(tmp <= 0){
	        		tmp = -1;
	        	}
	        	for(int i = 0;i<=tmp;i++){
	        	StatisticPaper practicePaper = modelPaperList.get(i);
	        	String practicePaperName = practicePaper.getPaperName();
	        	int practicePaperId = practicePaper.getPaperId();
	        	String practicePaperCreationTime  = df.format(practicePaper.getCreationTime());
	        	int practicePaperSubmitNum = practicePaper.getSubmitNumber();	        		        
	        %>
	        <div class="practice_paper_content">
		        <div class="paper_title"><%=practicePaperName %></div>
		        <div class="paper_details">
			        <div class="paper_create_time">creation time:<%=practicePaperCreationTime %></div>
			        <div class="paper_submit_number">submit number:<%=practicePaperSubmitNum %></div>
		        </div>
		        <div class="practice_paper_operate">
			        <form action="/Exam1/servlet/TCheckPaperContentServlet" method="post">
				        <input type="submit" class="btn_check_content" value="Check Content"/>
				        <input type="hidden" name="paper_id" value="<%=practicePaperId%>"/>				        
			        </form>
		        </div>
	        </div>
	        <%} %>
	    </div>    	                
        <%}else if(startIndex >= point[2] && endIndex<=point[3]){ %>            
      	<div id="practice_paper" class="practice_paper">
	        <div id="practice_paper_mark" class="practice_paper_mark">Practice Paper</div>
	    <%for(int i = startIndex - point[2];i< startIndex - point[2] + 5;i++){ 
        	StatisticPaper practicePaper = modelPaperList.get(i);
        	String practicePaperName = practicePaper.getPaperName();
        	int practicePaperId = practicePaper.getPaperId();
        	String practicePaperCreationTime  = df.format(practicePaper.getCreationTime());
        	int practicePaperSubmitNum = practicePaper.getSubmitNumber();	    
	    %>   	        
	        <div class="practice_paper_content">
		        <div class="paper_title"><%=practicePaperName %></div>
		        <div class="paper_details">
			        <div class="paper_create_time">creation time:<%=practicePaperCreationTime %></div>
			        <div class="paper_submit_number">submit number:<%=practicePaperSubmitNum %></div>
		        </div>
		        <div class="practice_paper_operate">
			        <form action="/Exam1/servlet/TCheckPaperContentServlet" method="post">
				        <input type="submit" class="btn_check_content" value="Check Content"/>
				        <input type="hidden" name="paper_id" value="<%=practicePaperId%>"/>				        
			        </form>
		        </div>
	        </div>
	    <%} %>    
        </div>
        <%}else if(startIndex >= point[2] && endIndex>point[3]){ %>
      	<div id="practice_paper" class="practice_paper">
	        <div id="practice_paper_mark" class="practice_paper_mark">Practice Paper</div>
	    <%for(int i = startIndex - point[2];i < modelPaperList.size();i++){ 
        	StatisticPaper practicePaper = modelPaperList.get(i);
        	String practicePaperName = practicePaper.getPaperName();
        	int practicePaperId = practicePaper.getPaperId();
        	String practicePaperCreationTime  = df.format(practicePaper.getCreationTime());
        	int practicePaperSubmitNum = practicePaper.getSubmitNumber();	    
	    %>            
	        <div class="practice_paper_content">
		        <div class="paper_title"><%=practicePaperName %></div>
		        <div class="paper_details">
			        <div class="paper_create_time">creation time:<%=practicePaperCreationTime %></div>
			        <div class="paper_submit_number">submit number:<%=practicePaperSubmitNum %></div>
		        </div>
		        <div class="practice_paper_operate">
			        <form action="/Exam1/servlet/TCheckPaperContentServlet" method="post">
				        <input type="submit" class="btn_check_content" value="Check Content"/>
				        <input type="hidden" name="paper_id" value="<%=practicePaperId%>"/>				        
			        </form>
		        </div>
	        </div>
	    <%}%>
	    </div>
	    <%}%>
		<form id="page_turning_form" action="/Exam1/servlet/TGetSelfPaperListServlet" method="get">
			 <div id="page_turning">
			     <div id="page_up_down">
			         <div id="page_up">
			             <div id="page_up_text">previous page</div>
			         </div>
			         <div id="page_down">
			             <div id="page_down_text">next page</div>
			         </div>              
			     </div>
			     <input id="page_num" name="page_num" type="hidden" value="<%=curPageNum%>"/>
			     <input id="max_page_num" type="hidden" value="<%=maxPageNum%>"/>
			     <input id="submit_page_num" name="submit_page_num" type="hidden" value=""/> 
			 </div>
		</form>			
	<%}else{%>
   	<div id="subjects_name"><%="Please select a course first" %></div>
   	<input type="hidden" id="ui_need" value="stretch"></input>
   	<%} %>
</div>              
</div>
</div>
</body>
</html>